<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>倒计时</title>
    <script src="./vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>
        <button @click="add()">添加</button>
        <button @click="allStop">全部暂停</button>
      </p>
      <hr />
      <p v-for="(item,index) in list" :key="index">
        <button @click="start(item,index)">开始</button>
        <button @click="stop()">暂停</button>
        <button @click="restart(item)">重置时间间隔</button>
        <button @click="del()">删除</button>
        <input type="text" @change="change(item,index)"   placeholder="请输入时间间隔"/>
      </p>
      <h1>{{item.number}}</h1>
      <hr>
    </div>
    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            list: [],
          };
        },
        methods: {
          add() {
            this.list.push({
              id: Date.now(),
              number: 0,
              step: 1,
              Interval: 1000,
            });
          },
          start(item) {
            console.log(item.step);
            let fn = function () {
              item.number += Number(item.step);
            };
            setInterval(() => {
              fn();
            }, interval);
          },
          change(item,index){
            console.log(item.value);
            console.log(this.value);
          },
          allStop() {
            clearInterval();
          },
          del(item, index) {
            clearInterval(item.number);
            this.list.splice(index, 1);
          },
          restart(item){
            clearTimeout(item.Interval);
            this.number = 0
          }
        },
      });
    </script>
  </body>
</html>
